package com.ruoyi.web.pojo.request.warning;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.ruoyi.common.utils.CommonUtils;
import com.ruoyi.common.utils.StringUtils;
import com.ruoyi.web.domain.warning.WarningInsectRecord;
import com.ruoyi.web.utils.BasePageQuery;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;

@Data
public class WarningInsectRecordRequest extends BasePageQuery {

    @ApiModelProperty("昆虫类型  1 一类害虫 2 二类害虫 3 其他")
    private Integer insectType;

    @ApiModelProperty("昆虫名字")
    private String insectName;

    @ApiModelProperty("昆虫编码")
    private String insectCode;

    @ApiModelProperty("虫情预警类型 1 始见预警 2 日高峰 3 月高峰")
    private Integer insectWarningType;

    @ApiModelProperty("开始时间")
    private String startTime;

    @ApiModelProperty("开始时间")
    private String endTime;

    @ApiModelProperty("用户id")
    private Long userId;

    /**
     * @desc  构建查询条件
     * @author fwx 2024/2/6 14:57
     **/
    public void bulidWrapper(QueryWrapper<WarningInsectRecord> query){
        //时间范围
        if(StringUtils.isNotBlank(this.getStartTime()) && StringUtils.isNotBlank(this.getEndTime())){
            query.lambda().between(WarningInsectRecord::getCrtTime,startTime, CommonUtils.computeTime(endTime,1));
        }

        //昆虫名字
        if(StringUtils.isNotBlank(this.getInsectName())){
            query.lambda().eq(WarningInsectRecord::getInsectName,this.getInsectName());
        }

        //昆虫类型
        if(this.getInsectType() != null){
            query.lambda().eq(WarningInsectRecord::getInsectType,this.getInsectType());
        }

        //虫情预警类型
        if(this.getInsectWarningType() != null){
            query.lambda().eq(WarningInsectRecord::getInsectWarningType,this.getInsectWarningType());
        }

        query.lambda().orderByDesc(WarningInsectRecord::getCrtTime);

    }
}
